module render.render;

import material.material;
import objects.abstractobject;
import scene.scene;
import scene.ray;
import scene.intersection;
import utils.color;
import utils.vector2;
import utils.vector3;

import std.math;

public struct RenderIntersection {
    Intersection inters;
    Vector3f normal; //normal of triangle
    AbstractObject object; //hit object
    uint objtriidx;     //triangle index relative to object
    Vector3f hitpoint;
    Vector2f texcoords; //coords at hitpoint
    Material material;
    Vector2f rdif_dTx, rdif_dTy;
    Vector3f rdif_dNx, rdif_dNy;

    Vector2f deltaTx, deltaTy;
}

public struct RenderContext {
    RGBColor color;
    Ray ray;
    Scene scene;
    int currecdepth;

    RenderIntersection rinters;

    public void addDirectionalLight(in RGBColor light, in Vector3f light_vector) {
        RGBColor matcol = rinters.material.value(*this, light_vector);
        color += light*fmax(0,rinters.normal*light_vector)*matcol;
    }
    public void addAmbientLight(in RGBColor light, float dist = 1.0f) {
        addDirectionalLight(light, rinters.normal*(dist));
    }
}
